'''
https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/description/
'''

from typing import List


class Solution:
    def maxProfit(self, prices: List[int], fee: int) -> int:
        buy, sell = -prices[0], 0   # 买了之后手里的钱，卖了之后手里的钱
        for price in prices:
            buy = max(buy, sell - price)
            sell = max(sell, buy + price - fee)
        return sell
